<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;

class OrderController extends Controller
{
    //
    public function index(Request $request)
    {
    	$where = [];
        $db = DB::table("distribution")->where("state","=","2");
        if($request->has("name")){
            $name = $request->input("name");
            //添加where模糊匹配条件
            $db->where("name","like","%{$name}%");
            $where['name'] = $name;
        }
    	
    	$list = $db->paginate(3);
    	// dd($list);
    	return view("admin.order.order",["list"=>$list,"where"=>$where]);
    }
    public function destroy($id)
    {
    	DB::table("distribution")->where("id",$id)->delete();
    	return redirect('admin/order');
    }
    public function edit( $id, Request $request)
    {
        DB::table("distribution")->where("id",$id)->update(['state' => '1']);
        $where = [];
        $db = DB::table("distribution")->where("state","=","2");
        if($request->has("name")){
            $name = $request->input("name");
            //添加where模糊匹配条件
            $db->where("name","like","%{$name}%");
            $where['name'] = $name;
        }
        
        $list = $db->paginate(3);
        // dd($list);
        return view("admin.order.order",["list"=>$list,"where"=>$where]);

    }
}
